package com.ruoyi.base.service.impl;

import java.util.List;

import com.ruoyi.base.domain.BaseMeterialStock;
import com.ruoyi.base.mapper.BaseMeterialStockMapper;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.base.mapper.BaseMeterialMoveMapper;
import com.ruoyi.base.domain.BaseMeterialMove;
import com.ruoyi.base.service.IBaseMeterialMoveService;

/**
 * 物料出入库记录操作Service业务层处理
 *
 * @author ruoyi
 * @date 2024-02-04
 */
@Service
public class BaseMeterialMoveServiceImpl implements IBaseMeterialMoveService {
    @Autowired
    private BaseMeterialMoveMapper baseMeterialMoveMapper;

    @Autowired
    private BaseMeterialStockMapper baseMeterialStockMapper;

    /**
     * 查询物料出入库记录操作
     *
     * @param id 物料出入库记录操作主键
     * @return 物料出入库记录操作
     */
    @Override
    public BaseMeterialMove selectBaseMeterialMoveById(Long id) {
        return baseMeterialMoveMapper.selectBaseMeterialMoveById(id);
    }

    /**
     * 查询物料出入库记录操作列表
     *
     * @param baseMeterialMove 物料出入库记录操作
     * @return 物料出入库记录操作
     */
    @Override
    public List<BaseMeterialMove> selectBaseMeterialMoveList(BaseMeterialMove baseMeterialMove) {
        List<BaseMeterialMove> baseMeterialMoves = baseMeterialMoveMapper.selectBaseMeterialMoveList(baseMeterialMove);
        for (BaseMeterialMove meterialMove : baseMeterialMoves) {
            BaseMeterialStock baseMeterialStock = baseMeterialStockMapper.selectBaseMeterialStockById(meterialMove.getMeterialId());
            meterialMove.setBaseMeterialStock(baseMeterialStock);
        }
        return baseMeterialMoves;
    }

    /**
     * 新增物料出入库记录操作
     *
     * @param baseMeterialMove 物料出入库记录操作
     * @return 结果
     */
    @Override
    public int insertBaseMeterialMove(BaseMeterialMove baseMeterialMove) {
        baseMeterialMove.setCreateTime(DateUtils.getNowDate());
        return baseMeterialMoveMapper.insertBaseMeterialMove(baseMeterialMove);
    }

    /**
     * 修改物料出入库记录操作
     *
     * @param baseMeterialMove 物料出入库记录操作
     * @return 结果
     */
    @Override
    public int updateBaseMeterialMove(BaseMeterialMove baseMeterialMove) {
        return baseMeterialMoveMapper.updateBaseMeterialMove(baseMeterialMove);
    }

    /**
     * 批量删除物料出入库记录操作
     *
     * @param ids 需要删除的物料出入库记录操作主键
     * @return 结果
     */
    @Override
    public int deleteBaseMeterialMoveByIds(Long[] ids) {
        return baseMeterialMoveMapper.deleteBaseMeterialMoveByIds(ids);
    }

    /**
     * 删除物料出入库记录操作信息
     *
     * @param id 物料出入库记录操作主键
     * @return 结果
     */
    @Override
    public int deleteBaseMeterialMoveById(Long id) {
        return baseMeterialMoveMapper.deleteBaseMeterialMoveById(id);
    }
}
